<!--
 * @Description:
 * @version:
 * @Author: sunqian_sr
 * @Date: 2022-12-02 18:34:49
 * @LastEditors: Andy
 * @LastEditTime: 2023-01-16 10:06:10
-->
<template>
  <x-page class="flex-row">
    <x-filter @search="handleSearch" @reset="handleReset">
      <!-- <x-filter-item :label="$t('system.user.account')">
        <el-input v-model="searchParams.account" :placeholder="$t('system.user.PleaseEnter')"></el-input>
      </x-filter-item> -->
      <x-filter-item :label="$t('system.user.user')">
        <el-input
          v-model="searchParams.queryCondition"
          :placeholder="$t('system.user.PleaseEnter')"
          clearable
        ></el-input>
      </x-filter-item>
      <!-- <x-filter-item :label="$t('system.user.role')">
        <x-select
          :placeholder="$t('system.user.choose')"
          v-model="searchParams.online"
          :options="onlineOptions"
          style="width: 100%"
        ></x-select>
      </x-filter-item> -->
      <x-filter-item :label="$t('system.user.status')">
        <x-select
          :placeholder="$t('system.user.choose')"
          v-model="searchParams.state"
          :options="statusOptions"
          style="width: 100%"
        ></x-select>
      </x-filter-item>
      <!-- <x-filter-item :label="$t('system.user.creatTime')">
        <el-date-picker
          v-model="searchParams.times"
          end-placeholder="结束日期"
          format="yyyy-MM-dd HH:mm:ss"
          start-placeholder="开始日期"
          style="width: 100%"
          type="datetimerange"
          value-format="yyyy-MM-dd HH:mm:ss"
        />
      </x-filter-item> -->
    </x-filter>
    <!--数据面板-->
    <x-data>
      <!--数据面板按钮插糟-->
      <template #tool>
        <el-row type="flex" class="tools" justify="space-between">
          <el-col :span="18">
            <el-button round size="small" @click="handleAddOrg()">
              {{ $t('organization.organiz.new') }}
            </el-button>
            <el-button round size="small" @click="handleExport()">
              {{ $t('organization.organiz.export') }}
            </el-button>
          </el-col>
          <el-col :span="6" class="tools-config">
            <x-column-config :columns="columns" @updateColumns="updateColumns" @on-refresh="loadData" />
          </el-col>
        </el-row>
      </template>
      <x-table
        ref="tableCom"
        :pagination="pagination"
        :data-source="tableData"
        :loading="loading"
        :row-key="'id'"
        @on-change="handleTableChange"
      >
        <el-table-column
          v-for="(item, index) in tableColumns"
          :key="index"
          :prop="item.prop"
          :fixed="item.fixed"
          :show-overflow-tooltip="true"
          :width="item.width || 100"
          :label="item.label"
          :sortable="'custom'"
        >
        </el-table-column>
        <el-table-column fixed="right" :label="$t('common.opeartion')" :align="'center'" width="160">
          <template slot-scope="scope">
            <more-table-actions :action-list="actions" :row="scope.row" @onActionClick="handleActions" />
          </template>
        </el-table-column>
      </x-table>
    </x-data>
    <by-org-add ref="byOrgComponent" @handleSuccess="loadData" />
  </x-page>
</template>
<script>
  import { TableListMixin } from '@package/utils'
  import ByOrgAdd from '../components/byOrgAdd.vue'
  import { columns, actions } from '../config/buyerOrg.js'
  import { apiDeleteByOrganiz, byOrganizPageListUrl } from '../api'
  import { EnumApiCode } from '../../../../../../globalEnum.js'

  export default {
    components: {
      ByOrgAdd
    },
    mixins: [TableListMixin],
    data() {
      return {
        byOrganizPageListUrl,
        columns,
        actions,
        treeProps: {
          label: 'shortName',
          children: 'children'
        }
      }
    },
    computed: {
      listUrl() {
        return this.byOrganizPageListUrl
      }
    },
    mounted() {},
    methods: {
      handleAddOrg(info) {
        this.$refs.byOrgComponent.handleOpen(info)
      },
      handleExport() {},
      handleActions({ key, data }) {
        switch (key) {
          case 'edit': // 修改组织基本信息
            this.$refs.byOrgComponent.handleOpen(data)
            break
          case 'delete':
            this.$confirm(this.$t('system.user.deleteSure'), this.$t('system.user.deletePrompt'), {
              confirmButtonText: this.$t('common.confirm'),
              cancelButtonText: this.$t('common.cancel'),
              type: 'warning'
            })
              .then((confirm) => {
                this.handleDeleteOrg(data.id)
              })
              .catch((cancel) => {})
            break
        }
      },
      /**
       * 删除组织的请求
       * @param deptId 组织ID string
       */
      async handleDeleteOrg(orgId) {
        const { code, msg } = await apiDeleteByOrganiz(orgId)
        if (code === EnumApiCode.Success) {
          this.$message.success(this.$t('system.user.successTips'))
          this.loadData()
        } else {
          this.$message.error(msg)
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
  @import '../../../common/assets/style/variables';

  .flex-row {
    display: flex;
    flex-direction: row;

    .left-panel {
      flex: 1;
      min-width: 300px;
      border-radius: 3px;
      background-color: $x-default-bg-color;

      .top {
        margin-bottom: 16px;
        padding: 12px 15px;
        border-bottom: 1px solid #e0e0e0;
      }

      .tree-container {
        height: calc(100% - 100px);
        padding: 20px 15px;
      }
    }

    .right-panel {
      display: flex;
      flex: 5;
      flex-direction: column;
      max-width: calc(100% - 300px);
      margin-left: 10px;
      color: #424242;
      border-radius: 3px;
      background-color: $x-default-bg-color;

      h4,
      h3 {
        font-size: 20px;
        font-weight: 500;
        margin: 0;
        // padding: 0 20px;

        span {
          line-height: 30px;
        }
      }

      h4 {
        margin-bottom: 19px;
        padding: 0 20px;

        .iconfont {
          font-size: 20px;
        }
      }

      h3 {
        padding-top: 20px;
      }

      .x-data-view {
        margin-top: 0;
        padding-top: 0;
        border-width: 0;
      }

      .tools {
        line-height: 42px;
        padding: 0 15px;
        border-radius: 3px;
        background-color: #eceff4;
      }

      .info-container {
        padding: 0 15px;
      }

      .info-hearder {
        font-size: 16px;

        // line-height: 60px;

        // margin-bottom: 10px;
        padding: 15px;
        color: $x-item-text-color;

        // border-bottom: 1px solid #e0e0e0;

        .el-icon-edit-outline {
          font-size: 18px;
          vertical-align: middle;
        }
      }
    }
  }
</style>
<style lang="scss">
  /* element滚动条组件 隐藏水平滚动条 */
  .tree-container .el-scrollbar__view {
    padding: 0 15px;
  }
  .tree-container .el-scrollbar__wrap {
    overflow-x: hidden;
  }

  .is-horizontal {
    display: none;
  }
</style>
